<?php
if (!defined('IN_IA')) {
	die('Access Denied');
}

global $_W, $_GPC;

if($_POST['token'] == $_W['token']){
	$ouid = $_POST['ouid'];
	$agentid = $_POST['auid'];
	
	$sql = 'SELECT `agentid`, `isagent`, `status` FROM '.tablename('ewei_shop_member').' WHERE `uniacid` = :uniacid AND `id` = :auid LIMIT 1';
	$uInfo = pdo_fetch($sql, array(':uniacid' => $_W['uniacid'], ':auid' => $agentid));
	
	if($uInfo == false || empty($uInfo)){
		message('未查到到该被选上级信息，请重试。','','error');
		exit();
	}
	
	if($uInfo['status'] != 1){
		message('被选上级已被禁用，无法更换。','','error');
		exit();
	}
	
	if($uInfo['isagent'] != 1){
		message('被选上级并非属于分销商，无法更换。','','error');
		exit();
	}
	
	$result = pdo_update('ewei_shop_member', array('agentid' => $agentid), array('id' => $ouid));
	
	if(!empty($result)){
		message('数据更新成功，等待2秒后，页面将自动刷新。','','success');
	}else{
		message('数据更新失败，请仔细检查。','','error');
	}
	
	
}else{
	echo '';
}


?>